<?php

class TaxonomyIndexAction extends CAction
{
	public $view = 'index';

	public $bundle;

	public function run()
	{
		$weights = isset($_POST['weight']) ? $_POST['weight'] : null;
		if (isset($_POST['saveWeight']) && $weights) {
			foreach ((array)$weights as $id => $weight) {
				Taxonomy::model()->updateWeightByPk($id, $weight);
			}
			Yii::app()->getUser()->setFlash('success', '保存权重成功');
			$this->getController()->redirect(array('index'));
		}
		$model = new Taxonomy('search');
		$model->unsetAttributes();
		$model->bundle = $this->bundle;
		if (isset($_GET['Taxonomy'])) {
			$model->attributes = $_GET['Taxonomy'];
		}
		$this->getController()->render($this->view, array('model' => $model));
	}
}